
/*
 * main implementation: use this 'C' sample to create your own application
 *
 */

#include "Mcu.h"
#include "Mcu_Cfg.h"
#include "Port.h"
#include "Port_Cfg.h"
#include "Dio.h"
#include "Dio_Cfg.h"
#include "Gpt.h"
#include "Gpt_Cfg.h"


/**
* @brief        Main function of the example
* @details      Initializez the used drivers and uses the Icu
*               and Dio drivers to toggle a LED on a push button
*/


uint8 flag = 0;
uint32 u16TimeElapsed = 0U;
uint32 u16TimeRemaining =0U;

void Gpt_Notification_Func(void){
    flag = (1U==flag)?0U:1U;
}

int main(void)
{
    uint8 RET = 0;
    /* Initialize the Mcu driver */
    Mcu_Init(&McuModuleConfiguration);

    Mcu_InitClock(McuClockSettingConfig_0);
#if (MCU_NO_PLL == STD_OFF)
    while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
    {
        /* Busy wait until the System PLL is locked */
    }

    Mcu_DistributePllClock();
#endif
    Mcu_SetMode(McuModeSettingConf_0);
    /* Initialize all pins using the Port driver */
    Port_Init(&PortConfigSet);
    Gpt_Init(&GptChannelConfigSet);
    Gpt_EnableNotification(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
    Gpt_StartTimer(GptConf_GptChannelConfiguration_GptChannelConfiguration_0,8000000);
    


    while (1)
    {
    	RET = Dio_ReadChannel(DioConf_DioChannel_DioChannel_KEY1);//PTC13
        u16TimeElapsed = Gpt_GetTimeElapsed(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
        u16TimeRemaining = Gpt_GetTimeRemaining(GptConf_GptChannelConfiguration_GptChannelConfiguration_0);
        if(u16TimeElapsed >= 4000000){
        	 flag = 1U;
        }else{
        	flag = 0U;
        }

		if(flag == 1)//PRESSED
		{
			Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_DioChannel_PTD0_LEDB, (Dio_LevelType)STD_LOW);//ON
            Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_DioChannel_PTD1_LEDY, (Dio_LevelType)STD_LOW);//ON
            Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_DioChannel_PTD16_LEDG, (Dio_LevelType)STD_LOW);//ON
            Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_DioChannel_PTD15_LEDR, (Dio_LevelType)STD_LOW);//ON

		}
		else
		{
			Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_DioChannel_PTD0_LEDB, (Dio_LevelType)STD_HIGH);//OFF
			Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_DioChannel_PTD1_LEDY, (Dio_LevelType)STD_HIGH);//OFF
			Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_DioChannel_PTD16_LEDG, (Dio_LevelType)STD_HIGH);//OFF
			Dio_WriteChannel((Dio_ChannelType)DioConf_DioChannel_DioChannel_PTD15_LEDR, (Dio_LevelType)STD_HIGH);//OFF


		}


    }
    while(1);
    return (0U);
}

